//
//  String+Date.swift
//  FoundationCustom
//
//  Created by ZhouJiatao on 2018/12/7.
//  Copyright © 2018 Unknow. All rights reserved.
//

import Foundation

public extension String {
    
    /// 将日期字符串转换为 Date 类型
    public func toDate(_ format: String = "yyyy-MM-dd HH:mm:ss") -> Date? {
        
        let template = format
        
        let formater = DateFormatter()
        
        formater.dateFormat = template
        
        return formater.date(from: self)
        
    }
    
    /// 将日期字符串的秒数去除
    public func cb_withoutSeconds() -> String {
        return self.toDate()?.string(withFormat: "yyyy-MM-dd HH:mm") ?? self
    }
    
    
    
}
